package cn.datawin.cmppclient.sender.util;

import cn.datawin.cmppclient.sender.entity.Provider;
import org.apache.commons.lang3.StringUtils;

public class SMSUtil {

    /**
     * @param provider
     * @param subCode
     * @return
     */
    public static String getSpNumber(Provider provider, String subCode) {
        subCode = StringUtils.defaultString(subCode, "");
        if (StringUtils.isNotEmpty(provider.getSp_Number())) {
            subCode = provider.getSp_Number() + subCode;
        }
//        String[] channelSpNumbers = provider.getSp_Number().split(",");
//        String channelSpNumber = channelSpNumbers[0];
//        if (channelSpNumbers.length > 1) {
//            channelSpNumber = channelSpNumbers[new Random().nextInt(channelSpNumbers.length)];
//        }
//        String spNumber = channelSpNumber + subCode;
        // TODO: 2022/11/29
//        Map<String, ChannelUtil.OtherParameter> otherParameters = com.hero.wireless.web.util.ChannelUtil.getParameter(channel);
//        int srcIdLength = ChannelUtil.getParameterIntValue(otherParameters, "src_id_length", 21);
//        if (spNumber.length() > srcIdLength) {
//            return spNumber.substring(0, srcIdLength);
//        }
        if (subCode.length() > 20) {
            return subCode.substring(0, 20);
        }

        return subCode;
    }

    /**
     * 根据byte数据获取编码字符串
     *
     * @param charSet
     * @return
     */
    public static String getCharsetByByte(byte charSet) {

        String dcs = "ASCII";
        switch (charSet) {
            case 0:
                dcs = "ASCII";
                break;
            case 4:
                dcs = "LATIN1";
                break;
            case 8:
                dcs = "UCS2";
                break;
            case 12:
                dcs = "RESERVED";
                break;
            case 15:
                dcs = "GBK";
                break;
        }
        return dcs;
    }

    /**
     * 根据编码字符串获取byte数据
     *
     * @param charSet
     * @return
     */
    public static byte getGeneralDataCodingDcs(String charSet) {
        byte dcs = 0x08;
        if (StringUtils.isEmpty(charSet)) {
            return dcs;
        }
        switch (charSet) {
            case "ASCII":
                dcs |= 0x00;
                break;
            case "LATIN1":
                dcs |= 0x04;
                break;
            case "UCS2":
                dcs |= 0x08;
                break;
            case "RESERVED":
                dcs |= 0x0C;
                break;
            case "GBK":
                dcs |= 0x0F;
                break;
        }
        return dcs;
    }


}
